package com.financial.service.integralpay.mq;

import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;


/**
 * 结算消息MQ配置文件
 * @Author cuich
 * @Date 2019-05-16
 */

@Configuration
public class FinancialIntegralPayMQConsumer {

    @Autowired
    private FinancialIntegralPayMessageListener integralPayMessageListener;

    public static final Logger LOGGER = LoggerFactory.getLogger(FinancialIntegralPayMQConsumer.class);

    public FinancialIntegralPayMQConsumer() {

    }

    @Bean
    public Consumer getYSAsynchronousSplitReceiptMQConsumerMsgListener() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.GROUP_ID, FinancialIntegralPayMQConfig.INTEGRAL_GROUPID);
        properties.put(PropertyKeyConst.AccessKey, FinancialIntegralPayMQConfig.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, FinancialIntegralPayMQConfig.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, FinancialIntegralPayMQConfig.NAMESRV_ADDR);
        Consumer consumer = ONSFactory.createConsumer(properties);

        try {
            consumer.subscribe(FinancialIntegralPayMQConfig.INTEGRAL_TOPIC, FinancialIntegralPayMQConfig.TAG_ALL,integralPayMessageListener);
            consumer.start();
            LOGGER.info("SettleConsumer is start !!!  groupId:{" + FinancialIntegralPayMQConfig.INTEGRAL_GROUPID+ "}");
        } catch (Exception var4) {
            LOGGER.error(String.format("SettleConsumer is error  groupId:{" + FinancialIntegralPayMQConfig.INTEGRAL_GROUPID + "}", var4.getMessage(), var4));
        }
        return consumer;
    }
}

